←Select platform

Save(string,BarcodeData[]) Method

Summary
Saves an array of BarcodeData objects to an XML file.
Syntax
C#
C++/CLI
Python
public static void Save( 
   string fileName, 
   BarcodeData[] data 
) 
public: 
static void Save(  
   String^ fileName, 
   array<BarcodeData^>^ data 
)  
def Save(self,fileName,] data): 

Parameters

fileName
Name of the XML file to create

data
An array of BarcodeData objects to save.

Remarks

The load/save methods are provided as helper methods for the user. The BarcodeEngine, BarcodeReader and BarcodeWriter do not use these methods internally. data can be null (Nothing in VB). This is the equivalent of saving an empty array.

To load the data previously saved into an XML file, use BarcodeData.Load(string fileName).

To save and load data to an XML stream, use BarcodeData.Save(Stream stream, BarcodeData[] data) and BarcodeData.Load(Stream stream).

Example

This example reads all the barcodes in an image, saves the data to an XML disk file. It will then load the data from this XML and print out the values.

C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Barcode; 
using Leadtools.ImageProcessing; 
 
 
public void BarcodeData_LoadSaveExample() 
{ 
   string imageFileName = Path.Combine(LEAD_VARS.ImagesDir, "Barcode1.tif"); 
   string xmlFileName = Path.Combine(LEAD_VARS.ImagesDir, "MyBarcodes.xml"); 
 
   // Create a Barcode engine 
   BarcodeEngine engine = new BarcodeEngine(); 
 
   // Load the image 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      using (RasterImage image = codecs.Load(imageFileName, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1)) 
      { 
         // Read all the barcodes 
         BarcodeData[] barcodes = engine.Reader.ReadBarcodes(image, LeadRect.Empty, 0, null); 
 
         // Print out the barcodes we found 
         Console.WriteLine("{0} barcodes found", barcodes.Length); 
         for (int i = 0; i < barcodes.Length; i++) 
         { 
            BarcodeData barcode = barcodes[i]; 
            Console.WriteLine("  {0} - {1} - {2}", i + 1, barcode.Symbology, barcode.Value); 
         } 
         Console.WriteLine("-----------------"); 
 
         // Save the barcodes to an XML file 
         BarcodeData.Save(xmlFileName, barcodes); 
 
         // Now load the data back and print them out 
         barcodes = BarcodeData.Load(xmlFileName); 
         Console.WriteLine("{0} barcodes loaded", barcodes.Length); 
         for (int i = 0; i < barcodes.Length; i++) 
         { 
            BarcodeData barcode = barcodes[i]; 
            Console.WriteLine("  {0} - {1} - {2}", i + 1, barcode.Symbology, barcode.Value); 
         } 
      } 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.5.9
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Barcode Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.